package com.bwie.coupon.controller;

import com.bwie.common.core.domain.PageResult;
import com.bwie.common.core.domain.Result;
import com.bwie.coupon.domain.dto.CouponExpiredDTO;
import com.bwie.coupon.domain.dto.CouponMerchantListDTO;
import com.bwie.coupon.domain.dto.MerchantAddCouponDTO;
import com.bwie.coupon.domain.vo.MerchantCouponDetailVo;
import com.bwie.coupon.domain.vo.MerchantCouponVo;
import com.bwie.coupon.service.CouponMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商家端优惠券
 */
@RestController
@RequestMapping("couponMerchant")
public class CouponMerchantController {
    /**
     * 注入
     */
    @Autowired
    private CouponMerchantService service;

    /**
     * 商家分页条件查询优惠券
     * @return
     */
   // @RequiresPermissions("coupon:merchant:list")
    @PostMapping("getMerchantCouponList")
    public PageResult<MerchantCouponVo> getMerchantCouponList(@RequestBody CouponMerchantListDTO couponMerchantListDTO){
        //调用方法
        PageResult<MerchantCouponVo> list = service.getMerchantCouponList(couponMerchantListDTO);
        //返回
        return list;
    }

    /**
     * 商家管理优惠券状态
     * @return
     */
    @PostMapping("couponExpired")
    public Result couponExpired(@RequestBody CouponExpiredDTO couponExpiredDTO){
        //调用方法
        service.couponExpired(couponExpiredDTO);
        //返回
        return Result.success();
    }

    /**
     * 商家删除优惠券
     * @param id
     * @return
     */
    @GetMapping("delCoupon/{id}")
    public Result delCoupon(@PathVariable Long id){
        //调用方法
        service.delCoupon(id);
        //返回
        return Result.success();
    }

    /**
     * 商家查询优惠券详情
     * @param id
     * @return
     */
    @GetMapping("getCouponDetail/{id}")
    public Result<MerchantCouponDetailVo> getCouponDetail(@PathVariable Long id){
        //查询优惠券详情
        MerchantCouponDetailVo merchantCouponDetailVo = service.getCouponDetail(id);
        //返回
        return Result.success(merchantCouponDetailVo);
    }

    /**
     * 商家添加优惠券
     * @return
     */
    @PostMapping("merchantAddCoupon")
    public Result MerchantAddCoupon(@RequestBody MerchantAddCouponDTO merchantAddCoupon){
        //商家添加优惠券
        service.merchantAddCoupon(merchantAddCoupon);
        //返回
        return Result.success();
    }
}
